﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using LX.Exceptions;
using LX.IO;

namespace LX.Core.IO
{
    public class LocalDistributionFileManager : IDistributionFileManager
    {
        /// <summary>
        /// 存储根目录,后面带/
        /// </summary>
        public string RootFolder { get; set; }

        /// <summary>
        /// 获取分区子文件夹,前面不带/，后面带/
        /// </summary>
        /// <returns></returns>
        public virtual string GetPartition()
        {
            return DateTime.Now.ToString("yyyy/MM/dd");
        }

        public DistributionFile SaveFile(byte[] data, string filename)
        {
            if(string.IsNullOrWhiteSpace(filename))
            {
                throw new BusinessValidException("文件名不能为空");
            }
            string file = System.IO.Path.GetFileName(filename);
            string relativepath = System.IO.Path.Combine(GetPartition(), file);
            string path = System.IO.Path.Combine(RootFolder, relativepath);
            FileHelper.SaveFile(data, path);
            return new DistributionFile { Area = null, Filepath = relativepath };
        }

        public DistributionFile SaveFile(System.IO.Stream stream, string filename)
        {
            throw new NotImplementedException();
        }

        public void DeleteFile(string area, string path)
        {
            throw new NotImplementedException();
        }


        public DistributionFile SaveFileWithMimetype(byte[] data, string mimetype)
        {
            throw new NotImplementedException();
        }

        public DistributionFile SaveFileWithMimetype(System.IO.Stream stream, string mimetype)
        {
            throw new NotImplementedException();
        }
    }
}
